package delegate4j;

import com.sun.istack.internal.Nullable;

import java.util.concurrent.FutureTask;

@FunctionalInterface
public interface IAction1<T> extends IDelegate {
    void invoke(T t) throws Exception;

    default FutureTask<Void> invokeAsync(T t, @Nullable Callback callback) {
        FutureTask<Void> futureTask = new FutureTask<>(() -> {
            invoke(t);
            if (callback != null) {
                callback.invoke(new InvokeData(this, new Object[]{t}));
            }
            return null;
        });
        ASYNC_DELEGATE_THREAD_POOL.submit(futureTask);
        return futureTask;
    }
}
